from AStock.ASAnalysis import ASDoubleGrowth, ASSingleGrowth
import argparse
from AStock.ASQuery import ASQuery_stock_pool


def _main_(args):
    single_growth = args.single_growth
    double_growth = args.double_growth
    report_date = args.report_date
    calc_date = args.calc_date
    stock_pool = args.stock_pool

    if stock_pool:
        df_pool = ASQuery_stock_pool()
        df_pool = df_pool.drop('name', axis=1)
    else:
        df_pool = None

    if single_growth:
        sg = ASSingleGrowth(report_date, calc_date=calc_date, df_pool=df_pool)
        sg.run(save_to_db=False, save_to_file=True)
    if double_growth:
        dg = ASDoubleGrowth(report_date, calc_date=calc_date, df_pool=df_pool)
        dg.run(save_to_db=False, save_to_file=True)


if __name__ == '__main__':
    argparser = argparse.ArgumentParser(description='export single/double growth')
    argparser.add_argument('--single-growth', action='store_true', default=False,
                           help='export single growth')
    argparser.add_argument('--double-growth', action='store_true', default=False,
                           help='export double growth')
    argparser.add_argument('-d', '--report-date', required=True,
                           help='report date')
    argparser.add_argument('-c', '--calc-date', required=False,
                           help='calc date, default is now')
    argparser.add_argument('--stock-pool', required=False, action='store_true',
                           help='export single/double growth of stocks from stock pool')
    args = argparser.parse_args()
    _main_(args)